package com.example.juc;

/**
 * @Description
 * @Date 2021/7/25
 * @Created by Jonathan
 */
//@Slf4j
public class MapDemo {
    static ThreadLocal<Integer> threadLocal = ThreadLocal.withInitial(() -> 100);

    public static void main(String[] args) {
        System.out.println("hello world");
        Thread thread1 = new Thread(() -> {
            try {
                //log.info("hello world");
                threadLocal.set(111);
                System.out.printf("hah:%d\n", threadLocal.get());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "t1");
        thread1.start();
        Thread thread2 = new Thread(() -> {
            try {
                //log.info("hello world");
                threadLocal.set(234);
                System.out.printf("hah:%d\n", threadLocal.get());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "t2");
        thread2.start();
        System.out.println("hello world");
        /*ConcurrentHashMap<S, Object> map = new ConcurrentHashMap<>();
        map.put(new S("1"), "1");
        map.put(new S("2"), "2");
        map.put(new S("3"), "3");
        map.put(new S("4"), "4");
        log.info("map:{}", map);
        log.info("map.get(4):{}", map.get(new S("4")));*/
        ThreadLocal<Integer> threadLocal = new ThreadLocal<>();
        threadLocal.set(111);
        System.out.printf("hah:%d\n", threadLocal.get());
    }

}

class S {
    String name;

    public S(String name) {
        this.name = name;
    }

    @Override
    public int hashCode() {
        return 100;
    }
}
